package xdpm.nhom16.BUS;

import java.util.List;

import xdpm.nhom16.DAO.*;
import xdpm.nhom16.DTO.ChiTietDichVuDTO;
import xdpm.nhom16.DTO.DuLieuDTO;
import xdpm.nhom16.GUI.ChiTietMenuAdapter;
import xdpm.nhom16.GUI.MenuDiaDiem;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;

public class BUSProvider
{
	public static ChiTietMenuAdapter getMenuAdapter(int iMaDuLieu, Context mContext)
	{
		// MySQLiteHelper dbhelper = new MySQLiteHelper(mContext);
		// SQLiteDatabase db = dbhelper.getReadableDatabase();

		SQLiteDatabase db = DataProvider.getInstance(mContext).getDb();

		ChiTietDichVuDAO daoChiTietDichVu = new ChiTietDichVuDAO(db);
		List<ChiTietDichVuDTO> lstChiTietDichVu = daoChiTietDichVu.getAllChiTietDichVuByMaDuLieu(iMaDuLieu);
		ChiTietMenuAdapter result = new ChiTietMenuAdapter(mContext, lstChiTietDichVu, null);
		return result;
	}

	public static boolean checkIfHasMenu(int iMaDuLieu, Context mContext)
	{
		// MySQLiteHelper dbhelper = new MySQLiteHelper(mContext);
		// SQLiteDatabase db = dbhelper.getReadableDatabase();

		SQLiteDatabase db = DataProvider.getInstance(mContext).getDb();

		ChiTietDichVuDAO daoChiTietDichVu = new ChiTietDichVuDAO(db);
		List<ChiTietDichVuDTO> lstChiTietDichVu = daoChiTietDichVu.getAllChiTietDichVuByMaDuLieu(iMaDuLieu);
		if (lstChiTietDichVu.size() == 0)
		{
			return false;
		}
		return true;
	}

	public static void onClickMenu(int iMaDuLieu, String tenDiaDiem, Context mContext)
	{
		Intent intent = new Intent();
		intent.setClass(mContext, MenuDiaDiem.class);
		intent.putExtra("MaDuLieu", iMaDuLieu);
		intent.putExtra("TenDiaDiem", tenDiaDiem);
		mContext.startActivity(intent);
	}
	public static DuLieuDTO getDuLieuDTO(int maDuLieu, Context mContext)	{		
		SQLiteDatabase db = DataProvider.getInstance(mContext).getDb();
		DuLieuDAO duLieuDAO = new DuLieuDAO(db);

		return duLieuDAO.getDTObyID(maDuLieu);
	}
	public static String getDiaChi(DuLieuDTO dto, Context mContext) {
		SQLiteDatabase db = DataProvider.getInstance(mContext).getDb();
		DuongDAO duongDAO = new DuongDAO(db);
		PhuongDAO phuongDAO = new PhuongDAO(db);
		QuanHuyenDAO quanHuyenDAO = new QuanHuyenDAO(db);
		String result = "";
		result += dto.getSoNha() + " " + duongDAO.getDTObyID(dto.getMaDuong()).getTenDuong() + ", Phường "
				+ phuongDAO.getDTObyID(dto.getMaPhuong()).getTenPhuong();
		String tenQuanHuyen = quanHuyenDAO.getDTObyID(dto.getMaQuanHuyen()).getTenQuanHuyen();
		if (tenQuanHuyen.equals("Bình Chánh") || tenQuanHuyen.equals("Nhà Bè")
				|| tenQuanHuyen.equals("Cần Giờ")
				|| tenQuanHuyen.equals("Hóc Môn")
				|| tenQuanHuyen.equals("Củ Chi")) {
			result += ", Huyện " + tenQuanHuyen;
		} else {
			result += ", Quận " + tenQuanHuyen;
		}
		return result;
	}
	public static String getTenDiaDiem(int maTenDiaDiem, Context mContext)	{		
		SQLiteDatabase db = DataProvider.getInstance(mContext).getDb();
		TenDiaDiemDAO tenDiaDiemDAO = new TenDiaDiemDAO(db);

		return tenDiaDiemDAO.getDTObyID(maTenDiaDiem).getTenDiaDiem();
	}
}
